#!/bin/sh

p1=$1
p2=$2

awk -F '\t' -v low="$p1" -v high="$p2" '
	BEGIN{bigwin=0;smallwin=0;count=0;lowc=0;draw=0;}
	NR>=1{
			if(NF==17)
			{
					count=count+1;
					if(low<=$12&&$12<=high || low<=$14&&$14<=high)
					{
						lowc=lowc+1;
							
							//smaller win
							if($8>$11 && $12<$13 && $12<$14)
									{
											smallwin=smallwin+1;
									}
							if($8<$11 && $14<$13 && $14<$12)
									{
											smallwin=smallwin+1;
									}
							//bigger win
							if($8>$11 && $12<$13 && $12<$14)
									{
											bigwin=bigwin+1;
									}
							if($8<$11 && $14>$13 && $14>$12)
									{
											bigwin=bigwin+1;
									}
							if($8==$11)
									{
											draw=draw+1;
									}
					}
			}
	}
	END{
		printf("range:%f~%f\n",low,high);
		printf("swin:%f\tall:%f\trate%f\n",smallwin,lowc,smallwin/lowc);
		printf("draw:%f\tall:%f\trate:%f\n",draw,lowc,draw/lowc);
		printf("bwin:%f\tall:%f\trate:%f\n",bigwin,lowc,bigwin/lowc);
	}	
' data.txt
